package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.Map;

import org.json.JSONObject;

import com.ymt.database.MongoDBDriver;

/************************************************************************************
 * @File name :LiveProductInfoWapper.java
 * @Author : xujiewei
 * @Date : 2016年6月28日
 * @Copyright : 洋码头
 * 商品合库 新库
 ************************************************************************************/
public class ProductListingModelWapper {
	MongoDBDriver mdd = YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNew("ProductListingModel");

	public ProductListingModelWapper()  {
	}
		

	public Map<String,Object> getProductId(String productId) throws Exception {
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",1);
	    
	    return list.size()>0?list.get(0):null;
	}
	    
	
	public boolean update(Map<String, Object> searchMap,Map<String, Object> updateMap) throws Exception{
		return  mdd.update(searchMap, updateMap).isUpdateOfExisting();
	}
	
	
	public int getCountByProductId(String productId) throws Exception{
		return mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",50).size();
	}
	
	
	public static void main(String[] args) throws Exception {
		
		Map<String,Object> a= new ProductListingModelWapper().getProductId("06fd7a67-7b98-490b-981b-b038007fa99b");
		JSONObject aa = new JSONObject(a);
		aa.getJSONArray("ActivityStockList").getJSONObject(0).getInt("ProductInActivityId");
		System.out.println(aa.getJSONArray("ActivityStockList").getJSONObject(0).getInt("ProductInActivityId"));
		
		//Mongo
		
	}    
	
	    
		    	
	
	    
}
